package com.woniu.sharepark.common.dao;

import com.woniu.sharepark.common.pojo.UserInfo;
import com.woniu.sharepark.leasesystem.common.pojo.IndentForm;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 用户个人信息数据访问层接口
 * @author xin
 * @date 2019/6/1 12:37
 */

@Repository
public interface UserInfoDAO {
    /**
    * 通过主键删除用户信息
    * @title deleteByPrimaryKey
    * @param uId 主键id
    * @return: int
    * @author xin
    * @date 2019/6/1 12:38
    */
    int deleteByPrimaryKey(Integer uId);

    /**
    * 插入用户信息
    * @title insert
    * @param record 用户信息
    * @return: int
    * @author xin
    * @date 2019/6/1 12:38
    */
    int insert(UserInfo record);

    /**
    * 动态插入用户信息
    * @title insertSelective
    * @param record 用户信息
    * @return: int
    * @author xin
    * @date 2019/6/1 12:38
    */
    int insertSelective(UserInfo record);

    /**
    * 通过主键查询用户信息
    * @title selectByPrimaryKey
    * @param uId 主键id
    * @return: com.woniu.sharepark.pojo.UserInfo
    * @author xin
    * @date 2019/6/1 12:38
    */
    UserInfo selectByPrimaryKey(Integer uId);

    /**
    * 通过主键动态修改用户信息
    * @title updateByPrimaryKeySelective
    * @param record 用户信息
    * @return: int
    * @author xin
    * @date 2019/6/1 12:38
    */
    int updateByPrimaryKeySelective(UserInfo record);

    /**
    * 通过主键修改用户信息
    * @title updateByPrimaryKey
    * @param record 用户信息
    * @return: int
    * @author xin
    * @date 2019/6/1 12:38
    */
    int updateByPrimaryKey(UserInfo record);
    /**
    * 通过评论方id查找评论方姓名
    * @title selectUNameByUId
    * @param uId 评论方id
    * @return java.lang.String
    * @author litong
    * @date 2019/6/4 14:47
    **/
    String selectUNameByUId(int uId);

    /**
    *  减少当前用户余额
    * @title updateReduceMoney
    * @param getuId,getoTotalmoney
    * @return int
    * @author DELL
    * @date 2019/6/4 16:12
    **/

    int updateReduceMoney(@Param("uId") Integer getuId,@Param("totalMoney") Double getoTotalmoney);

    /**
     * 查询当前账户余额
     * @param getlId
     * @return
     */
    UserInfo selectUserInfoByLid(Integer getlId);

    /**
    * 查询当前用户相关信息与订单信息
    * @title selectUserInfoAndOrder
    * @param uId
    * @return com.woniu.sharepark.common.pojo.UserInfo
    * @author DELL
    * @date 2019/6/19 15:27
    **/

    UserInfo selectUserInfoAndOrder(Integer uId);

    /**
    * 查询流水信息
    * @title findIndentForm
    * @param  uId
    * @return com.woniu.sharepark.common.pojo.UserInfo
    * @author DELL
    * @date 2019/6/20 10:42
    **/

    @Select("select * from userinfo where u_id = #{uId}")
    @Results({
            @Result(id = true,column = "u_id",property = "uId"),
            @Result(column = "u_id",property = "indentForms",many = @Many(select="selectIndents"))
    })
    UserInfo findIndentForm(Integer uId);

    /**
    * s
    * @title selectIndents
    * @param uId
    * @return java.util.List
    * @author DELL
    * @date 2019/6/20 12:41
    **/

    @Select("select * from indent_form where if_drawee = #{uId}")
    List<IndentForm> selectIndents(Integer uId);

    /**
    * 按车位查找小区账户
    * @title selectCommunityUserinfo
    * @param id
    * @return com.woniu.sharepark.common.pojo.UserInfo
    * @author DELL
    * @date 2019/6/20 20:05
    **/
    @Select("select c.* from carpark a INNER JOIN community b on a.com_id = b.com_id INNER JOIN userinfo c ON c.l_id = b.l_id where ID = #{id} ")
    UserInfo selectCommunityUserinfo(Integer id);

    /**
     * 根据当前用户id查找当前用户信誉值
     *
     * @param uId Param Description
     * @return java.lang.Integer
     * @Author Zongjie.Li
     * @Date 2019/6/21
     * @Version 1.0
     */
    Integer getCredit(Integer uId);
}